package com.cargohu.aishouyu.member.controller;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.framework.page.Paging;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.member.dto.MemberSignAddDTO;
import com.cargohu.aishouyu.member.dto.MemberSignUpdateDTO;
import com.cargohu.aishouyu.member.req.MemberSignRequest;
import com.cargohu.aishouyu.member.resp.MemberSignDetailVo;
import com.cargohu.aishouyu.member.resp.MemberSignResponse;
import com.cargohu.aishouyu.member.service.MemberSignService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户签到记录 控制器
 *
 * @author yww
 * @since 2023-11-29
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_ADMIN_PATH+"/member-sign")
@Tag(name = "用户签到记录")
public class MemberSignController {

    @Autowired
    private MemberSignService memberSignService;

    /**
     * 添加用户签到记录
     *
     * @param memberSignAddDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    @Operation(summary = "添加用户签到记录")
    public ApiResult addMemberSign(@Valid @RequestBody MemberSignAddDTO memberSignAddDTO) throws Exception {
        boolean flag = memberSignService.addMemberSign(memberSignAddDTO);
        return ApiResult.result(flag);
    }

    /**
     * 修改用户签到记录
     *
     * @param memberSignUpdateDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    @Operation(summary = "修改用户签到记录")
    public ApiResult updateMemberSign(@Valid @RequestBody MemberSignUpdateDTO memberSignUpdateDTO) throws Exception {
        boolean flag = memberSignService.updateMemberSign(memberSignUpdateDTO);
        return ApiResult.result(flag);
    }

    /**
     * 删除用户签到记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除用户签到记录")
    public ApiResult deleteMemberSign(@PathVariable Long id) throws Exception {
        boolean flag = memberSignService.deleteMemberSign(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取用户签到记录详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/get/{id}")
    @Operation(summary = "用户签到记录详情")
    public ApiResult<MemberSignDetailVo> getMemberSign(@PathVariable Long id) throws Exception {
        MemberSignDetailVo memberSignDetailVo = memberSignService.getMemberSignById(id);
        return ApiResult.success(memberSignDetailVo);
    }

    /**
     * 用户签到记录分页列表
     *
     * @param memberSignRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/page")
    @Operation(summary = "用户签到记录分页列表")
    public ApiResult<MemberSignResponse> getMemberSignList(@Valid @RequestBody MemberSignRequest memberSignRequest) throws Exception {
        Paging<MemberSignResponse> paging = memberSignService.getMemberSignList(memberSignRequest);
        return ApiResult.success(paging);
    }

}
